
/*
 * telaCadastroVeiculo.java
 *
 * 
 */
package Telas;

import gerenciadorveiculos.Veiculo;
import BD.daoVeiculo;
import java.util.Vector;
import javax.swing.*;

/**
 *
 * @author Gabriel
 */
public class telaCadastroVeiculo extends javax.swing.JFrame {

    /** Creates new form telaCadastroVeiculo */
    public telaCadastroVeiculo() {
       
        initComponents();
    }
    private Vector anos(){
        Vector vet =new Vector();
        for(int i=1950;i<=2010;i++)
            vet.add(i);
        return vet;
    }

    

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        mainPanel = new javax.swing.JPanel();
        placaLabel = new javax.swing.JLabel();
        marcaLabel = new javax.swing.JLabel();
        modeloLabel = new javax.swing.JLabel();
        tipoLabel = new javax.swing.JLabel();
        anoModeloLabel = new javax.swing.JLabel();
        precoVendaLabel = new javax.swing.JLabel();
        novoButton = new javax.swing.JButton();
        salvarButton = new javax.swing.JButton();
        jTextPlaca = new javax.swing.JTextField();
        jTextMarca = new javax.swing.JTextField();
        jTextModelo = new javax.swing.JTextField();
        jTextChassi = new javax.swing.JTextField();
        jTextPrecoVenda = new javax.swing.JTextField();
        jComboAnoModelo = new javax.swing.JComboBox();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Cadastro Veículo");

        mainPanel.setName("mainPanel"); // NOI18N

        placaLabel.setForeground(new java.awt.Color(255, 0, 51));
        placaLabel.setText("Placa:");
        placaLabel.setName("placaLabel"); // NOI18N

        marcaLabel.setForeground(new java.awt.Color(255, 51, 51));
        marcaLabel.setText("Marca:");
        marcaLabel.setName("marcaLabel"); // NOI18N

        modeloLabel.setForeground(new java.awt.Color(255, 51, 51));
        modeloLabel.setText("Modelo:");
        modeloLabel.setName("modeloLabel"); // NOI18N

        tipoLabel.setForeground(new java.awt.Color(255, 51, 51));
        tipoLabel.setText("Chassi:");
        tipoLabel.setName("tipoLabel"); // NOI18N

        anoModeloLabel.setText("Ano Modelo:");
        anoModeloLabel.setName("anoModeloLabel"); // NOI18N

        precoVendaLabel.setText("Preço Venda:");
        precoVendaLabel.setName("precoVendaLabel"); // NOI18N

        novoButton.setText("Limpar Dados");
        novoButton.setName("novoButton"); // NOI18N
        novoButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                novoButtonActionPerformed(evt);
            }
        });

        salvarButton.setText("Salvar");
        salvarButton.setName("salvarButton"); // NOI18N
        salvarButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                salvarButtonActionPerformed(evt);
            }
        });

        jTextPlaca.setName("jTextPlaca"); // NOI18N

        jTextMarca.setName("jTextMarca"); // NOI18N

        jTextModelo.setName("jTextModelo"); // NOI18N

        jTextChassi.setName("jTextChassi"); // NOI18N

        jTextPrecoVenda.setName("jTextPrecoVenda"); // NOI18N

        jComboAnoModelo.setModel(new javax.swing.DefaultComboBoxModel(anos()));
        jComboAnoModelo.setName("jComboAnoModelo"); // NOI18N
        jComboAnoModelo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboAnoModeloActionPerformed(evt);
            }
        });

        org.jdesktop.layout.GroupLayout mainPanelLayout = new org.jdesktop.layout.GroupLayout(mainPanel);
        mainPanel.setLayout(mainPanelLayout);
        mainPanelLayout.setHorizontalGroup(
            mainPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, mainPanelLayout.createSequentialGroup()
                .addContainerGap()
                .add(mainPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                    .add(mainPanelLayout.createSequentialGroup()
                        .add(novoButton)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(salvarButton))
                    .add(org.jdesktop.layout.GroupLayout.LEADING, anoModeloLabel)
                    .add(org.jdesktop.layout.GroupLayout.LEADING, mainPanelLayout.createSequentialGroup()
                        .add(mainPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(tipoLabel)
                            .add(modeloLabel)
                            .add(marcaLabel)
                            .add(placaLabel)
                            .add(precoVendaLabel))
                        .add(18, 18, 18)
                        .add(mainPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(jTextMarca, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 462, Short.MAX_VALUE)
                            .add(jTextModelo, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 462, Short.MAX_VALUE)
                            .add(jTextChassi, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 462, Short.MAX_VALUE)
                            .add(jTextPlaca, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 455, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                            .add(jTextPrecoVenda, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 44, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
                    .add(org.jdesktop.layout.GroupLayout.LEADING, mainPanelLayout.createSequentialGroup()
                        .add(88, 88, 88)
                        .add(jComboAnoModelo, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 109, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 347, Short.MAX_VALUE)))
                .addContainerGap())
        );
        mainPanelLayout.setVerticalGroup(
            mainPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(mainPanelLayout.createSequentialGroup()
                .add(52, 52, 52)
                .add(mainPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(placaLabel)
                    .add(jTextPlaca, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 19, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                .add(mainPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(marcaLabel)
                    .add(jTextMarca, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(mainPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(modeloLabel)
                    .add(jTextModelo, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                .add(mainPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(tipoLabel)
                    .add(jTextChassi, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .add(42, 42, 42)
                .add(mainPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(precoVendaLabel)
                    .add(jTextPrecoVenda, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                .add(mainPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(anoModeloLabel)
                    .add(jComboAnoModelo, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 149, Short.MAX_VALUE)
                .add(mainPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(salvarButton)
                    .add(novoButton))
                .addContainerGap())
        );

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(mainPanel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(mainPanel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(24, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jComboAnoModeloActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboAnoModeloActionPerformed

      
    }//GEN-LAST:event_jComboAnoModeloActionPerformed

    private void salvarButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_salvarButtonActionPerformed
         if(verificarCampos())
            JOptionPane.showMessageDialog(null,"Campos Marcados sao Obrigatorios"," ",0);
        else{
             Veiculo veiculo = new Veiculo();
             
             veiculo.setChassi(jTextChassi.getText().toString());
             veiculo.setMarca(jTextMarca.getText().toString());
             veiculo.setModelo(jTextModelo.getText().toString());
             
             veiculo.setPlaca(jTextPlaca.getText().toString());
             veiculo.setPrecoVenda(jTextPrecoVenda.getText().toString());
             
             
             veiculo.setAno(jComboAnoModelo.getSelectedItem().toString());
             veiculo.cadastrarVeiculo();

             JOptionPane.showMessageDialog(null,"Veiculo cadastrado com sucesso"," ",1);
             limparCampos();

        }
    }//GEN-LAST:event_salvarButtonActionPerformed

    private void novoButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_novoButtonActionPerformed
        limparCampos();
    }//GEN-LAST:event_novoButtonActionPerformed

    private void limparCampos(){
       
        jTextChassi.setText(" ");
        jTextMarca.setText(" ");
        jTextModelo.setText(" ");
       
        jTextPrecoVenda.setText(" ");
       
        jTextPlaca.setText(" ");

    }

    public boolean verificarCampos(){
        if(jTextPlaca.getText().isEmpty()||jTextChassi.getText().isEmpty()||jTextMarca.getText().isEmpty()||
                jTextModelo.getText().isEmpty())
            return true;
        return false;
    }
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new telaCadastroVeiculo().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel anoModeloLabel;
    private javax.swing.JComboBox jComboAnoModelo;
    private javax.swing.JTextField jTextChassi;
    private javax.swing.JTextField jTextMarca;
    private javax.swing.JTextField jTextModelo;
    private javax.swing.JTextField jTextPlaca;
    private javax.swing.JTextField jTextPrecoVenda;
    private javax.swing.JPanel mainPanel;
    private javax.swing.JLabel marcaLabel;
    private javax.swing.JLabel modeloLabel;
    private javax.swing.JButton novoButton;
    private javax.swing.JLabel placaLabel;
    private javax.swing.JLabel precoVendaLabel;
    private javax.swing.JButton salvarButton;
    private javax.swing.JLabel tipoLabel;
    // End of variables declaration//GEN-END:variables
}
